﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;
using Service.Interface;
using Dao.Interface;

namespace Service
{
    public class ReplyService : Service<Reply>, IReplyService
    {
        public IPageRepository PageRepository;

        /// <summary>
        /// 获取回复分页集合
        /// </summary>
        /// <param name="pageID">共享页ID</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageCount">总页数</param>
        /// <returns></returns>
        public IList<Reply> LoadAllReply(int pageID, int pageIndex, int pageSize, out int pageCount)
        {
            return ((IReplyRepository)(this.CurrentRepository)).LoadAllReply(pageID, pageIndex, pageSize, out pageCount).ToList();
        }

        /// <summary>
        /// 保存回复同时更新共享页回复数
        /// </summary>
        /// <param name="reply"></param>
        /// <returns></returns>
        public void SaveReplyAndUpdatePageReplyCount(Reply reply)
        {
            //保存回复
            ((IReplyRepository)(this.CurrentRepository)).Save(reply);
            //更新回复数
            Page page = this.PageRepository.Get(reply.Page.ID);
            page.ReplyCount = page.Replys.Count;
            this.PageRepository.Update(page);
        }

        /// <summary>
        /// 查询页总回复数
        /// </summary>
        /// <param name="pageID">页ID</param>
        /// <returns></returns>
        public int SelectReplyCount(object pageID)
        {
            return ((IReplyRepository)(this.CurrentRepository)).SelectReplyCount(pageID);
        }
    }
}
